<%@ page language="Java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    
    <title>添加图书信息</title>        
 </head>
 <body>
 <%request.setCharacterEncoding("UTF-8"); %>
 <jsp:useBean id="book" class="com.mingrisoft.jdbc.Book"></jsp:useBean>
 <jsp:setProperty property="*" name="book"/>
 <%
 	try{
 		Class.forName("com.mysql.jdbc.Driver");
 		String url = "jdbc:mysql://localhost:3306/test";
 		String username = "root";
 		String password = "1234";
 		Connection conn = DriverManager.getConnection(url,username,password);
 		String sql = "insert into tb_books(name,price,bookCount,author)value(?,?,?,?)";
 		PreparedStatement ps = conn.prepareStatement(sql);
 		ps.setString(1, book.getName());
 		ps.setDouble(2, book.getPrice());
 		ps.setInt(3, book.getBookCount());
 		ps.setString(4, book.getAuthor());
 		int row = ps.executeUpdate();
 		if(row > 0){
 			out.print("成功添加了" + row + "条数据");
 		}
 		ps.close();
 		conn.close();
 	}catch(Exception e){
 		out.print("图书信息添加失败");
 		e.printStackTrace();
 	}
 %>
 <br>
 <a href="book_info.jsp">返回</a>
 </body>
</html>